package guoanmaker.operator.business.service;

import guoanmaker.operator.business.model.OperatorSpaceAppointment;
import guoanmaker.operator.business.repository.OperatorSpaceAppointmentRepository;
import guoanmaker.operator.helper.common.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *  
 *
 * @ClassName: OperatorSpaceAppointmentService 
 * @Description: OperatorSpaceAppointmentService 
 * @author: huZhaoyu 
 * @date 2017/6/28 下午4:56 
 */
@Service
public class OperatorSpaceAppointmentService implements OperatorSpaceAppointmentServiceInterface {
    private final OperatorSpaceAppointmentRepository operatorSpaceAppointmentRepository;

    @Autowired
    public OperatorSpaceAppointmentService(OperatorSpaceAppointmentRepository operatorSpaceAppointmentRepository) {
        this.operatorSpaceAppointmentRepository = operatorSpaceAppointmentRepository;
    }

    @Override
    public OperatorSpaceAppointment saveSpaceAppointment(OperatorSpaceAppointment operatorSpaceAppointment) {
        return operatorSpaceAppointmentRepository.save(operatorSpaceAppointment);
    }

    @Override
    public List<OperatorSpaceAppointment> getAllSpaceAppointment() {
        return operatorSpaceAppointmentRepository.findAll();
    }

    @Override
    public Page<OperatorSpaceAppointment> getAllSpaceAppointmentByPage(Integer page, Integer size) {
        return operatorSpaceAppointmentRepository.findAll(new PageRequest(page, size));
    }

    @Override
    public void deleteSpaceAppointmentById(String id) {
        operatorSpaceAppointmentRepository.delete(id);
    }

    @Override
    public OperatorSpaceAppointment getSpaceAppointmentById(String id) {
        return operatorSpaceAppointmentRepository.findOne(id);
    }

    @Override
    public ArrayList<OperatorSpaceAppointment> findByAppointmentNameContainingAndAppointmentPhoneContainingOrderByCreateDateDesc(String appointmentName, String appointmentPhone, Integer page, Integer size) {

        return operatorSpaceAppointmentRepository.findByAppointmentNameContainingAndAppointmentPhoneContainingOrderByCreateDateDesc(appointmentName, appointmentPhone, new PageRequest(page, size));
    }

}
